package com.tnt.springbootrabbmitmq.provider.fanoutexchange;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description
 * @Author zhuangxl
 * @Date 2021-01-25 20:26
 */
@RestController
@RequestMapping("/fanout/provider")
public class FanoutExchangeProviderController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * @Description: 生产消息进入队列
     * @Author: zhuangxl
     * @Date: 21/1/25 20:35
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     **/
    @RequestMapping("/sendMessage")
    public Map<String, Object> sendMessage(){

        String messageId = UUID.randomUUID().toString();
        String messageContent = "I am Fanout Exchange Message from FanoutExchangeProviderController!";
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("messageId", messageId);
        paramsMap.put("messageContent", messageContent);
        paramsMap.put("createTime", createTime);

        rabbitTemplate.convertAndSend("fanoutExchange", "", paramsMap);

        return paramsMap;

    }

}
